package FileInformation;



import FileInformation.helpers.ColumnCounter;
import FileInformation.helpers.EndOfLineChecker;
import FileInformation.helpers.ExcelInformationRetriever;
import FileInformation.helpers.ExtensionRetriever;
import FileInformation.helpers.LineCounter;
import FileInformation.helpers.TextLineIgnorer;
import FileInformation.providers.DataSeparatorProvider;
import FileInformation.utils.DataType;
import FileInformation.utils.EndOfLineType;
import FileInformation.utils.NumberParser;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: Nobody
 * Date: 25.04.11
 * Time: 00:38
 * To change this template use File | Settings | File Templates.
 */
public class FileInformation implements Serializable {

    private LineCounter lineCounter;
    private TextLineIgnorer textLineIgnorer;
    private ColumnCounter columnCounter;
    private EndOfLineChecker endOfLineChecker;
    private final File file;
    private ExcelInformationRetriever excelInformationRetriever;
    private ExtensionRetriever extensionRetriever;
    private DataSeparatorProvider dataSeparatorProvider = new DataSeparatorProvider();

    public FileInformation(String fileName) throws IOException {
       this(new File(fileName));
       
    }
    public FileInformation(File file) throws IOException  {
        this.file = file;
        start();
    }
     private void start() throws IOException  {
            initHelpers(file);
            lineCounter.execute();
            endOfLineChecker.execute();
            textLineIgnorer.execute();
            columnCounter.setFirstDataRowNumber(textLineIgnorer.getFirstDataRowNumber());
            columnCounter.execute();
            excelInformationRetriever.execute();
    }

    private void initHelpers(File file) {
        lineCounter = new LineCounter(file);
        textLineIgnorer = new TextLineIgnorer(file);
        columnCounter = new ColumnCounter(file,new NumberParser());
        endOfLineChecker = new EndOfLineChecker(file);
        excelInformationRetriever = new ExcelInformationRetriever(file);
        extensionRetriever = new ExtensionRetriever(file);
    }

    public DataSeparatorProvider getDataSeparatorProvider(){
        return dataSeparatorProvider;
    }

    public String getFileExtension() {
         extensionRetriever.execute();
         return extensionRetriever.getExtension();
    }

    public DataType getFileDataType() {
        String extension = getFileExtension();
        return DataType.convertFromExtension(extension);
    }

    public char getLineStarter() {
        return textLineIgnorer.getLineStarter();
    }

    
    public String selectedExcelSheet() {
        return excelInformationRetriever.getChoosedSheetName();
    }

    public String[] getExcelSheetNames() {
        return excelInformationRetriever.getSheetNames();
    }

    public void setChoosedSheetName(String name) {
        excelInformationRetriever.setChoosedSheetName(name);
    }

    public String getChoosedSheetName() {
        return excelInformationRetriever.getChoosedSheetName();
    }

    public int getColumns() {
        return columnCounter.getColumns();
    }

    public File getFile() {
        return file;
    }

    public int getFirstDataRowNumber() {
        return textLineIgnorer.getFirstDataRowNumber();
    }

    public EndOfLineType getEndLineType() {
        return endOfLineChecker.getEndLineType();
    }

    public int getLines() {
        return lineCounter.getLines();
    }

    public void setEndOfType(EndOfLineType endOfLineType) {
        this.endOfLineChecker.setEndLineType(endOfLineType);
    }

    public boolean isExcel7File() {
        return extensionRetriever.isExcel7File();
    }

    public boolean isExcel2003File() {
        return extensionRetriever.isExcel2003File();
    }

    public boolean isExcelFile() {
        return extensionRetriever.isExcelFile();
    }

    public boolean isGdaFile() {
        return extensionRetriever.isGdaFile();
    }

    public static void main(String[] args) throws IOException {
        FileInformation fileInformation = new FileInformation("data\\test.odt");
    }
}
